﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinFormCenter.common
{
    internal class ArrayUtil
    {
        /// <summary>
        /// 把一维数组转成二维数组
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="values"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        public static T[,] OneDimensional2Two<T>(T[] values, int column) {
            //根据元素个数和列数计算出行数
            var row = values.Length / column;
            if (values.Length % column != 0) {
                row++;
            }
            T[,] result= new T[row, column];
            for (int i = 0; i < row; i++) {
                for (int j = 0; j < column; j++) {
                    result[i, j] = values[i * j + j];
                }
            }
            return result;
        }

    }
}
